requirejs.config({
    paths: {
        g2plot: "/assets/addons/health/libs/g2plot",
    }
})
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'g2plot'], function ($, undefined, Backend, Table, Form, G2Plot) {
    var Controller = {
        index: () => {
            new Vue({
                el: '#trackingUrlIndex',
                data() {
                    return {
                        tableData: [{
                            date: '2016-05-02',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1518 弄'
                        }, {
                            date: '2016-05-04',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1517 弄'
                        }, {
                            date: '2016-05-01',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1519 弄'
                        }, {
                            date: '2016-05-03',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1516 弄'
                        }],
                        currentPage: 1,
                        pageSize: 10,
                        lists: [],
                        totalPage: 0,
                        codeMap: [],
                        activeTabName: '',
                        ringRightData: [
                            { item: '微信支付', type: 'wechatPay', count: 10, percent: 20 },
                            { item: '支付宝支付', type: 'alipayPay', count: 10, percent: 20 },
                            { item: '钱包支付', type: 'walletPay', count: 10, percent: 40 },
                            { item: '其他', type: 'otherPay', count: 10, percent: 20 }
                        ],
                        codeData: null,
                    }
                },
                created() {
                    this.codeMap = Config.code_map;
                    this.activeTabName = this.codeMap[0].code;
                },
                mounted() {
                },
                watch: {
                    activeTabName(value) {
                        this.currentPage = 1;
                        this.getCodeData(value)
                        this.getListsPage(value)
                    }
                },
                methods: {
                    getCodeData(code) {
                        let that = this;
                        Fast.api.ajax({
                            url: 'health/tracking/url/index',
                            loading: true,
                            type: 'GET',
                            data: {
                                code: code
                            }
                        }, function (ret, res) {
                            that.codeData = ret;
                            return false;
                        })
                    },
                    getListsPage(code) {
                        let that = this;
                        Fast.api.ajax({
                            url: 'health/tracking/url/lists',
                            loading: true,
                            type: 'GET',
                            data: {
                                code: code,
                                page: this.currentPage,
                                limit: this.pageSize
                            }
                        }, function (ret, res) {
                            that.lists = ret.data;
                            that.totalPage = ret.total;
                            return false;
                        })
                    },
                    handleCurrentChange(val) {
                        this.currentPage = val;
                        this.getListsPage(this.activeTabName)
                    },
                    tabClick(tab, event) {
                        this.activeTabName = tab.name;
                    },
                }
            })
        }
    }

    return Controller;
})